import { MockRequest } from '@delon/mock'

const list: any[] = []
const total = 50

for (let i = 0; i < total; i += 1) {
  list.push({
    id: i + 1,
    disabled: i % 6 === 0,
    href: 'https://ant.design',
    avatar: [
      'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
      'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
    ][i % 2],
    no: `TradeCode ${i}`,
    title: `一个任务名称 ${i}`,
    owner: '曲丽丽',
    description: '这是一段描述',
    callNo: Math.floor(Math.random() * 1000),
    status: Math.floor(Math.random() * 10) % 4,
    updatedAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
    createdAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
    progress: Math.ceil(Math.random() * 100),
  })
}

function genData(params: any) {
  let ret = [...list]
  const pi = +params.pi,
    ps = +params.ps,
    start = (pi - 1) * ps

  if (params.no) {
    ret = ret.filter(data => data.no.indexOf(params.no) > -1)
  }

  return { total: ret.length, list: ret.slice(start, ps * pi) }
}

function saveData(id: number, value: any) {
  const item = list.find(w => w.id === id)
  if (!item) return { msg: '无效用户信息' }
  Object.assign(item, value)
  return { msg: 'ok' }
}

export const POSTEVENT = {
  '/user': (req: MockRequest) => genData(req.queryString),
  '/user/:id': (req: MockRequest) => list.find(w => w.id === +req.params.id),
  'POST /user/:id': (req: MockRequest) => saveData(+req.params.id, req.body),
  '/comb/postEvent': {
    status: 0,
    count: 2,
    total: 2,
    page: 1,
    size: 10,
    data: [
      {
        id: 1,
        insCode: '12333',
        agentCode: '214124',
        storeCode: '2325235',
        storeNameEN: 'aabb',
        storeName: '小店',
        createAt: '2019-10-19',
        score: '30'
      },
      {
        id: 1,
        insCode: '12333',
        agentCode: '214124',
        storeCode: '2325235',
        storeNameEN: 'aabb',
        storeName: '小店',
        createAt: '2019-10-19',
        score: '30'
      }
    ]
  },
  '/comb/postEvent/:id': {
    id: 1,
    insCode: '12333',
    agentCode: '214124',
    storeCode: '2325235',
    storeNameEN: 'aabb',
    storeName: '小店',
    createAt: '2019-10-19',
    score: '30',
    city: '上海',
    currency: 'CNY',
    address: '23ls-dlsjg---wer',
    status: 'init',
    contactMail: '233444@qq.com',
    contactName: '李白',
    industyType: '33superMarket',
    region: '中国',
    rules: [
      {
        schemeCode: '11222',
        ruleId: '2333',
        ruleDes: '规则一',
        threshold: 100,
        thresholdDes: '授权金额',
        score: 10,
        mode: '授权',
        createTime: '1230-19-29',
        updateTime: '2019-12-19',
      },
      {
        schemeCode: '334444',
        ruleId: '233',
        ruleDes: '规则二',
        threshold: 100,
        thresholdDes: '授权金额',
        score: 10,
        mode: '授权',
        createTime: '1230-19-29',
        updateTime: '2019-12-19',
      }
    ]
  },
  '/comb/postRiskEvent/rule/trade': {
    total: 12,
    page: 1,
    pageSize: 10,
    data: [
      {
        orderNum: '22332',
        createdAt: '2019-10-19',
        transScene: 'transScene',
        transChannel: 'transChannel',
        transAmt: 'transAmt',
        termCode: 'termCode',
        status: 'init'
      },
      {
        orderNum: '22332',
        createdAt: '2019-10-19',
        transScene: 'transScene',
        transChannel: 'transChannel',
        transAmt: 'transAmt',
        termCode: 'termCode',
        status: 'released'
      }
    ]
  },
  '/comb/postRiskEvent/rule/trade/commen': {
    orderNum: '22332',
    createdAt: '2019-10-19',
    transScene: 'transScene',
    transChannel: 'transChannel',
    transAmt: 'transAmt',
    termCode: 'termCode',
    comment: '评论一'
  }
}
